﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.MaHaiBo.API.DTOS;
using RBAC.MaHaiBo.Entity.Traceability;
using RBAC.MaHaiBo.Service.TraceabilityService;
using MediatR;
using RBAC.MaHaiBo.API.Application.Command.PlotInfoCommand;

namespace RBAC.MaHaiBo.API.Controllers
{
    /// <summary>
    /// 图片控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PlotInfoController : ControllerBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<PlotInfoController> logger;
        /// <summary>
        /// 图片服务层
        /// </summary>
        IPlotInfoService PlotInfoS;
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="PlotInfoS">图片服务层</param
        /// <param name="mediator">中介者</param>
        public PlotInfoController(ILogger<PlotInfoController> logger, IPlotInfoService PlotInfoS, IMediator mediator)
        {
            this.logger = logger;
            this.PlotInfoS = PlotInfoS;
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加产品检验报告
        /// </summary>
        /// <param name="tracingId">溯源编号</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddTracingsurfacePlot(AddTracingsurfacePlotCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {

                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片控制器】添加产品检验报告 出错");
                throw;
            }
            return result;
        }

        /// <summary>
        /// 产品检验报告
        /// </summary>
        /// <param name="tracingId">溯源编号</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> TracingsurfacePlotlist([FromQuery]TracingsurfacePlotlistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片控制器】产品检验报告 出错");
                throw;
            }
            return result;
        }

        /// <summary>
        /// 添加动态证
        /// </summary>
        /// <param name="farmid">养殖编号</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddHygienePlot([FromQuery]AddHygienePlotCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】添加产品检验报告 出错");
                throw;
            }
            return result;
        }

        /// <summary>
        /// 动态证
        /// </summary>
        /// <param name="farmid">养殖编号</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> HygienePlotInfolist([FromQuery]HygienePlotInfolistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data = await mediator.Send(request);

            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】动态证 出错");
                throw;
            }
            return result;
        }
        /// <summary>
        /// 添加企业
        /// </summary>
        /// <param name="firmid">企业编号</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddFirmPlot([FromQuery]AddFirmPlotCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);

            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】添加企业 出错" + ex.Message);
                throw;
            }
            return result;
        }
        /// <summary>
        /// 企业图片
        /// </summary>
        /// <param name="firmid">企业编号</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> FirmPlotInfolist([FromQuery]FirmPlotInfolistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data = await mediator.Send(request);

            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】企业图片 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 添加相关资料
        /// </summary>
        /// <param name="slaughterid">屠宰id</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddSlaughterPlotInfolist([FromQuery]AddSlaughterPlotInfolistCommand request)
        {
            ApiResult<int> result = new ApiResult<int> ();
            try
            {
                result.Code = await mediator.Send (request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】添加相关资料 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 相关资料图片
        /// </summary>
        /// <param name="slaughterid">屠宰id</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据集合</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> SlaughterPlotInfolist([FromQuery]SlaughterPlotInfolistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data= await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】相关资料图片 出错" + ex.Message);
                throw;
            }
            return result;
        }
        /// <summary>
        /// 添加深加工相关资料
        /// </summary>
        /// <param name="Deepprocessingid">深加工id</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddDeepProcessingPlotInfolist([FromQuery]AddDeepProcessingPlotInfolistCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】添加深加工相关资料 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 深加工相关资料图片
        /// </summary>
        /// <param name="Deepprocessingid">深加工id</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据集合</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> DeepProcessingPlotInfolist([FromQuery]DeepProcessingPlotInfolistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data= await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】深加工相关资料图片 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 添加原材相关资料
        /// </summary>
        /// <param name="RawMaterialid">原材id</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddRawMaterialPlotInfolist([FromQuery]AddRawMaterialPlotInfolistCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】添加原材相关资料 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 原材相关资料图片
        /// </summary>
        /// <param name="RawMaterialid">原材id</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据集合</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> RawMaterialPlotInfolist([FromQuery]RawMaterialPlotInfolistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】原材相关资料图片 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 添加辅料相关资料
        /// </summary>
        /// <param name="Accessoriesid">辅料id</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddAccessoriesPlotInfolist([FromQuery]AddAccessoriesPlotInfolistCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】添加辅料相关资料 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 辅料相关资料图片
        /// </summary>
        /// <param name="Accessoriesid">辅料id</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据集合</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> AccessoriesPlotInfolist([FromQuery]AccessoriesPlotInfolistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】辅料相关资料图片 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 添加添加剂相关资料
        /// </summary>
        /// <param name="Additiveid">添加剂id</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddAdditivePlotInfolist([FromQuery]AddAdditivePlotInfolistCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】添加添加剂相关资料 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 添加剂相关资料图片
        /// </summary>
        /// <param name="Additiveid">添加剂id</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据集合</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> AdditivePlotInfolist([FromQuery] AdditivePlotInfolistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】添加剂相关资料图片 出错" + ex.Message);
                throw;
            }
            return result;
        }
        /// <summary>
        /// 包材添加相关资料
        /// </summary>
        /// <param name="PackingMaterialsid">包材id</param>
        /// <param name="lot">批次</param>
        /// <param name="surfacePlot">图片</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ADDPackingMaterialsPlotInfolist([FromQuery]ADDPackingMaterialsPlotInfolistCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await  mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】包材添加相关资料 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 包才相关资料图片
        /// </summary>
        /// <param name="PackingMaterialsid">包才id</param>
        /// <param name="lot">批次</param>
        /// <returns>返回数据集合</returns>
        [HttpGet]
        public async Task<ApiResult<List<PlotInfo>>> PackingMaterialsPlotInfolist([FromQuery]PackingMaterialsPlotInfolistCommand request)
        {
            ApiResult<List<PlotInfo>> result = new ApiResult<List<PlotInfo>>();
            try
            {
                result.Data = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】包才相关资料图片 出错" + ex.Message);
                throw;
            }
            return result;
        }

        /// <summary>
        /// 删除图片
        /// </summary>
        /// <param name="Pid">图片编号</param>
        /// <returns>返回受影响行数</returns>
        [HttpPut]
        public async Task<ApiResult<int>> DelPlotInfo([FromQuery] DelPlotInfoCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                logger.LogError("【图片服务层】删除图片 出错" + ex.Message);
                throw;
            }
            return result;
        }

    }
}
